# 列表推导式
print([i for i in range(10)])
print([i for i in range(10) if i % 2 == 0])
print([(i, j) for i in range(1, 3) for j in range(3)])

# 字典推导式
print({i: i**2 for i in range(1, 5)})

# 两个列表合并为一个字典
list1 = ['name', 'age', 'gender']
list2 = ['Tom', 20, 'man', 'test']
dict1 = {list1[i]: list2[i] for i in range(min(len(list1),len(list2)))}
print(dict1)

# 提取字典中的目标数据
print({key: value for key, value in dict1.items() if key == 'age'})


# 集合推导式
list3 = [1, 2, 2]
print({i**2 for i in list3})

